/**
 * Package: IO.Ports
 */

// Ports
#define PortA 0
#define PortB 1
#define PortC 2
#define PortD 3
#ifdef MEGA128
#define PortE 4
#define PortF 5
#define PortG 6
#endif

#ifdef MEGA32
#define PORT_SW1 26
#define PORT_SW2 27
#endif

#ifdef MEGA128
#define PORT_SW1 36
#define PORT_SW2 38
#endif

/// <summary>Configures the port for input or output direction. If a bit is set, then the Pin corresponding to the bit position is switched to output.</summary>
/// <param name="port">Port number.</param>
/// <param name="val">Output byte.</param>
void Port_DataDir           $opc(0x01)(byte port, byte val);

/// <summary>Writes a byte to the specified port. Only the Pins of port that are configured for output return a valid value on their bit position. If a Pin is configured as input, a Port_Write() will set an internal pull-up resistor on (bit = 1) or off (bit = 0).</summary>
/// <param name="port">Port number.</param>
/// <param name="val">Output byte.</param>
void Port_Write             $opc(0x02)(byte port, byte val);

/// <summary>Reads a byte from the specified port. Only the Pins of port that are configured for input return a valid value on their bit position.</summary>
/// <param name="port">Port number.</param>
/// <returns>Port byte value.</returns>
byte Port_Read              $opc(0x03)(byte port);

/// <summary>Configures one bit (Pin) of a port for input or output direction. If a bit is set, then the Pin corresponding to the bit position is switched to output.</summary>
/// <param name="portbit">Port bit number.</param>
/// <param name="val">0=Input, 1= Output.</param>
void Port_DataDirBit        $opc(0x2B)(byte portbit, byte val);

/// <summary>Sets the value of a Pin that is configured for output. If a Pin is configured as input, a Port_WriteBit() will set an internal pull-up resistor on (bit = 1) or off (bit = 0).</summary>
/// <param name="portbit">Bit number of port.</param>
/// <param name="val">Bit value (0 or 1).</param>
void Port_WriteBit          $opc(0x2C)(byte portbit, byte val);

/// <summary>Reads the value of a Pin that is configured for input.</summary>
/// <param name="portbit">Bit number of port.</param>
/// <returns>Bit value (0 or 1).</returns>
byte Port_ReadBit           $opc(0x2D)(byte portbit);

/// <summary>Inverts all Bits on the specified port. Only the Pins of port that are configured for output will show their value as port output on their bit position. If a Pin is configured as input, this will set an internal pull-up resistor on (bit = 1) or off (bit = 0).</summary>
/// <param name="port">Port number.</param>
void Port_Toggle	    $opc(0x86)(byte port);

/// <summary>Inverts the value of a Pin that is configured for output. If a Pin is configured as input, this will set an internal pull-up resistor on (bit = 1) or off (bit = 0).</summary>
/// <param name="portbit">Bit number of port.</param>
void Port_ToggleBit		 	$opc(0x87)(byte portbit);